package org.gangcai.mac.shop.common;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.support.multidex.MultiDex;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.Utils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;

import com.nostra13.universalimageloader.core.DisplayImageOptions;

import org.gangcai.mac.shop.BuildConfig;
import org.gangcai.mac.shop.R;
import org.gangcai.mac.shop.bean.UserDataBean;
import org.gangcai.mac.shop.bean.UserDataBean;
import org.gangcai.mac.shop.manager.RetrofitManager;
import org.gangcai.mac.shop.manager.RetrofitManageres;
import org.gangcai.mac.shop.manager.RetrofitManagers;
import org.gangcai.mac.shop.util.UtilsTool;

import cn.jpush.android.api.JPushInterface;
import retrofit2.Retrofit;

/**
 * Created by meijun on 17-12-5.
 */

public class BaseApplication extends Application {
    public boolean isLogined ;
    public int productListType = 1; //1: 商品列表, 2: 产品搜索结果列表
    public UserDataBean.UserBean getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(UserDataBean.UserBean loginUser) {
        this.loginUser = loginUser;
        if (this.loginUser !=null){
            isLogined = true;
        }else{
            isLogined = false;
        }
    }

    private UserDataBean.UserBean loginUser ;
    private static BaseApplication instance;
    private static BaseApplication baseApplication;

/*
    static {//static 代码段可以防止内存泄露
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.soliderColor, R.color.textColorDark);//全局设置主题颜色
                layout.setEnableScrollContentWhenLoaded(true);
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
    }
*/

    public static BaseApplication getInstance()
    {
        if (instance == null) {
            instance = new BaseApplication();
        }
        return instance;
    }

    public static Context getAppContext() {
        return instance;
    }

    @Override
    public void onCreate() {
        instance = this;
        super.onCreate();
        RetrofitManager.init(this);
        RetrofitManagers.init(this);
        RetrofitManageres.init(this);
        Utils.init(this);
        UtilsTool.init(this);
        initSwipe();
        JPushInterface.setDebugMode(BuildConfig.DEBUG);
        JPushInterface.init(this);
        baseApplication = this;
    }

    private void initShareSdk() {
        //    MobSDK.init(this);
    }


    private void initSwipe() {
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
            MultiDex.install(this);
    }
}
